const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
// 定义了一些文件夹的路径
const ROOT_PATH = path.resolve(__dirname);
const APP_PATH = path.resolve(ROOT_PATH, 'src');

module.exports = {
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        loader: 'babel-loader',
        include: APP_PATH
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'postcss-loader']
        })
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      // // 加载图片并置于images文件夹下
      // {
      //   test: /\.(png|jpg|jpeg|gif)(\?.+)?$/,
      //   loader: 'url-loader?limit=8192&name=/images/[name]_[hash:8].[ext]'
      // },
      // // 加载字体并置于fonts文件夹下
      // {
      //   test: /\.(eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
      //   loader: 'url-loader?limit=8192&name=/fonts/[name]_[hash:8].[ext]'
      // },
      {
        test: require.resolve('jquery'),
        use: [{
            loader: 'expose-loader',
            options: 'jQuery'
          },{
            loader: 'expose-loader',
            options: '$'
          }]
        }
    ]
  },

  resolve: {
    extensions: ['.js', '.vue', '.jsx'], //后缀名自动补全
  },

  plugins: [
    new ExtractTextPlugin({
      filename: "css/[name]_[contenthash:8].css"
    }),
    //provide $, jQuery and window.jQuery to every script
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery",
      "window.$": "jquery"
    }),

    // avoid publishing when compilation failed.
    new webpack.NoEmitOnErrorsPlugin()
  ]
};
